//
//  FileIOManager.h
//  LowPassFilter_Standalone
//
//  Created by kadlubek47 on 13.03.2013.
//  Copyright (c) 2013 kadlubek47. All rights reserved.
//

#ifndef __LowPassFilter_Standalone__FileIOManager__
#define __LowPassFilter_Standalone__FileIOManager__

#include <AudioToolbox/ExtendedAudioFile.h>

/*
    @TODO:
    - many channels
    - cleaning
    - too long names
*/

class FileIOManager {
public:
    FileIOManager();
    ~FileIOManager();
    
    void read(const char* pathToFile, int wantedBytePerSample, long long int* length /*out*/, void*** channels /*out*/, int* numOfChannels /*out*/, unsigned int* samplingRate /*out*/);
    void write(void** channels, const char* pathToNewFile);
    
    static void printDescription(AudioStreamBasicDescription descr);

private:
    int numOfChannels_;
    
    SInt64 inFileLength_;
    ExtAudioFileRef inFileReference_;
    AudioBufferList inFileBuffer_;
    AudioStreamBasicDescription inFileDescription_;
    
    UInt32 numberFramesRead_;
    AudioStreamBasicDescription bufferDescription_;

    AudioBufferList outFileBuffer_;
    AudioStreamBasicDescription outFileDescription_;
    
    //read
    void getFileDescription();
    void setConvertingBufferParameters(int bytePerSample);
    void readFileIntoBuffer();
    void getAudio(long long int* length /*out*/, void*** channels /*out*/, int* numberOfChannels /*out*/);
    
    //write
    void setAudio(void** channel);
    void setConvertingOutFileParameters();
    
    
};

#endif /* defined(__LowPassFilter_Standalone__FileIOManager__) */
